<template>
  <div class="login">
    <div class="login-top">
      <div class="logo">
        <img src="../assets/img/login&register/svg/logo-black.svg" alt="" />
      </div>
      <h2>登录</h2>
    </div>
    <div class="login-information">
      <div class="information">
        <div>
          <input type="text" v-model="phone" @blur="phoneBlur" placeholder="请输入手机号" />
          <span>{{phoneInput}}</span>
        </div>
        <div>
          <input type="password" v-model="password" @blur="passwordBlur" placeholder="请输入密码" />
          <span>{{passwordInput}}</span>
          <div class="forget">
            <a href="">忘记密码</a>
          </div>
        </div>
        <div>
          <input class="submit" @click="loginRequest(userInfo)" type="submit" value="登录" />
        </div>
      </div>
      <!-- <div class="register-link">
        <a :to="'/account/register'">注册DJI账号</a>
      </div> -->
      <router-link :to="'/account/register'">注册DJI账号</router-link>
    </div>
  </div>
</template>

<script>
import {login} from '../assets/js/request.js'
export default {
  data() {
    return {
      // name: "",
      phone: "",
      password: "",

      phoneInput: "",
      passwordInput:"",

    };
  },
  computed: {
    userInfo() {
      return {
        phone: this.phone,
        password: this.password,
      };
    },
  },
  methods: {   
        // 手机号格式检验
        phoneBlur() {
          if(this.phone === '') {
            this.phoneInput = '手机号不能为空'
          }else {
            this.phoneInput = ''
          }
        },
        passwordBlur() {
          if(this.password === '') {
            this.passwordInput = '密码不能为空'
          }else {
            this.passwordInput = ''
          }
        },

        loginRequest(data) {
          // console.log(data);
          if((this.password!=='' && this.passwordInput === '') && (this.phone!=='' && this.phoneInput ==='')) {
            console.log(data);
            login(data)
            .then(res=>{
              console.log(res);
              localStorage.setItem("token",res.token)
              localStorage.setItem('loginId',res.id)
              // console.log(res.token);
              this.$router.push('/index')
            },res=>{
              console.log('手机号或密码输入错误');
              alert('手机号或密码输入错误')
            })
          }else {
            if(this.phone === '') {
              this.phoneInput = '手机号不能为空'
            }else {
              this.phoneInput = ''
            }
            if(this.password === '') {
              this.passwordInput = '密码不能为空'
            }else {
              this.passwordInput = ''
            }
          }
        }

    }
};
</script>

<style lang="scss" scope>
.login {
  width: 50%;
  padding: 78px 30px;
  .login-top {
    .logo {
      img {
        width: 70px;
      }
    }
    h2 {
      font-size: 30px;
      margin: 18px 0 18px;
    }
  }
  .login-information {
    border-top: 2px solid black;
    width: 315px;
    margin: 0 auto;
    padding-top: 24px;
    .information {
      div {
        position: relative;
        input {
          width: 315px;
          height: 52px;
          border: 0.5px solid black;
          display: block;
          margin: 9px auto 36px;
          padding: 0 18px;
        }
        span {
          display: block;
          text-align: left;
          color: red;
          // margin: 10px 0;
          z-index: 10;
          // display: none;
          position: absolute;
          top: 58px;
          left: 0;
        }
        .forget {
          position: absolute;
          top: 16px;
          right: 10px;
        }
      }
      .submit {
        background-color: skyblue;
      }
    }
    .register-link {
      margin: 24px 0;
    }
  }
}
</style>
<style scoped>
/* For demo */
.ant-carousel >>> .slick-slide {
  text-align: center;
  /* height: 480px; */
  /* line-height: 480px; */
  background: #364d79;
  overflow: hidden;
}

.ant-carousel >>> .custom-slick-arrow {
  width: 25px;
  height: 25px;
  font-size: 25px;
  color: #fff;
  background-color: rgba(31, 45, 61, 0.11);
  opacity: 0.3;
}
.ant-carousel >>> .custom-slick-arrow:before {
  display: none;
}
.ant-carousel >>> .custom-slick-arrow:hover {
  opacity: 0.5;
}

.ant-carousel >>> .slick-slide .img {
  /* background-repeat: initial;  */
  /* background-size: 600px 480px; */
  /* z-index: 10; */
  /* height: 480px; */
}
</style>